package com.deer.wms.base.system.web.ware;

import com.deer.wms.base.system.model.bar.BarCode;
import com.deer.wms.base.system.model.bar.BarCodeDto;
import com.deer.wms.base.system.model.bill.InserData;
import com.deer.wms.base.system.model.ware.WareConveyor;
import com.deer.wms.base.system.service.ware.WareConveyorService;
import com.deer.wms.common.core.controller.BaseController;
import com.deer.wms.common.core.page.TableDataInfo;
import com.deer.wms.common.core.result.CommonCode;
import com.deer.wms.common.core.result.Result;
import com.deer.wms.common.core.result.ResultGenerator;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/system/wareConveyor")
public class WareConveyorController extends BaseController {
    @Autowired
    private WareConveyorService wareConveyorService;

    private String prefix = "system/wareConveyor";

    @RequiresPermissions("system:wareConveyor:view")
    @GetMapping()
    public String areaInfo()
    {
        return prefix + "/wareConveyor";
    }

    /**
     * 显示全部信息，条件查询
     * @param wareConveyor
     * @return
     */
    @PostMapping("/findList")
    @ResponseBody
    @Transactional
    public TableDataInfo findList(WareConveyor wareConveyor) {
        startPage();
        List<WareConveyor> list = wareConveyorService.findList(wareConveyor);
        return getDataTable(list);
    }

    /**
     * 禁用、启用
     * @param wareConveyor
     * @return
     */
    @PostMapping("/startOrEnd")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result startOrEnd(WareConveyor wareConveyor){
        Integer state = wareConveyor.getState();
        if(state==0){
            int startResult= wareConveyorService.startState(wareConveyor.getId());
            if(startResult==0){
                return ResultGenerator.genFailResult(CommonCode.SERVICE_ERROR, "false");
            }
        }if (state==1){
            int endResult = wareConveyorService.endState(wareConveyor.getId());
            if(endResult==0){
                return ResultGenerator.genFailResult(CommonCode.SERVICE_ERROR, "false");
            }
        }
        return ResultGenerator.genSuccessResult();
    }


}
